<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Hoodoo::Services::Session::MockDalliClient</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Class</span>
            Hoodoo::Services::Session::MockDalliClient
                <span class="parent">&lt;
                    Object
                </span>
        </h1>
        <ul class="files">
            <li><a href="../../../../files/lib/hoodoo/services/services/session_rb.html">lib/hoodoo/services/services/session.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>Mock known uses of Dalli::Client with test implementations. Use explicitly,
or as an RSpec implicit mock via something like this:</p>

<pre><code>allow( Dalli::Client ).to receive( :new ).and_return( Hoodoo::Services::Session::MockDalliClient.new )
</code></pre>

<p>…whenever you need to stub out real Memcached. You will probably want to
add:</p>

<pre><code>before :all do # (or &quot;:each&quot;)
  Hoodoo::Services::Session::MockDalliClient.reset()
end
</code></pre>

<p>…to “clean out Memcached” before or between tests. You can check the
contents of mock Memcached by examining <a
href="MockDalliClient.html#method-c-store">::store</a>&#39;s hash of data.</p>

    </div>








    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>B</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-c-bypass">bypass</a>,
              </li>
              <li>
                <a href="#method-c-bypass-3F">bypass?</a>
              </li>
          </ul>
        </dd>
        <dt>D</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-delete">delete</a>
              </li>
          </ul>
        </dd>
        <dt>G</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-get">get</a>
              </li>
          </ul>
        </dd>
        <dt>R</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-c-reset">reset</a>
              </li>
          </ul>
        </dd>
        <dt>S</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-set">set</a>,
              </li>
              <li>
                <a href="#method-i-stats">stats</a>,
              </li>
              <li>
                <a href="#method-c-store">store</a>
              </li>
          </ul>
        </dd>
    </dl>










    <!-- Methods -->
      <div class="sectiontitle">Class Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-c-bypass">
              <b>bypass</b>( bypass_boolean )
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-c-bypass" name="method-c-bypass" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Pass <code>true</code> to bypass the mock client (subject to the caller
reading <a href="MockDalliClient.html#method-c-bypass-3F">::bypass?</a>) to
e.g. get test code coverage on real Memcached. Pass <code>false</code>
otherwise.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-bypass_source')" id="l_method-c-bypass_source">show</a>
              </p>
              <div id="method-c-bypass_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 677</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">bypass</span>( <span class="ruby-identifier">bypass_boolean</span> )
  <span class="ruby-identifier">@@bypass</span> = <span class="ruby-identifier">bypass_boolean</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-bypass-3F">
              <b>bypass?</b>()
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-c-bypass-3F" name="method-c-bypass-3F" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>If <code>true</code>, bypass this class and use real Dalli::Client; else
don&#39;t. Default return value is <code>false</code>.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-bypass-3F_source')" id="l_method-c-bypass-3F_source">show</a>
              </p>
              <div id="method-c-bypass-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 686</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">bypass?</span>
  <span class="ruby-identifier">@@bypass</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-reset">
              <b>reset</b>()
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-c-reset" name="method-c-reset" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Wipe out all saved data.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-reset_source')" id="l_method-c-reset_source">show</a>
              </p>
              <div id="method-c-reset_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 669</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">reset</span>
  <span class="ruby-identifier">@@store</span> = {}
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-store">
              <b>store</b>()
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-c-store" name="method-c-store" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>For test analysis, return the hash of &#39;memcached&#39; mock data.</p>

<p>Entries are referenced by the key you used to originally store them; values
are hashes with “:expires_at” giving an expiry time or “nil” and “:value”
giving your stored value.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-store_source')" id="l_method-c-store_source">show</a>
              </p>
              <div id="method-c-store_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 663</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">store</span>
  <span class="ruby-identifier">@@store</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
      <div class="sectiontitle">Instance Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-delete">
              <b>delete</b>( key )
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-i-delete" name="method-i-delete" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Remove data for the given key.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-delete_source')" id="l_method-i-delete_source">show</a>
              </p>
              <div id="method-i-delete_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 727</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">delete</span>( <span class="ruby-identifier">key</span> )
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">@@store</span>.<span class="ruby-identifier">has_key?</span>( <span class="ruby-identifier">key</span> )
    <span class="ruby-identifier">@@store</span>.<span class="ruby-identifier">delete</span>( <span class="ruby-identifier">key</span> )
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-get">
              <b>get</b>( key )
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-i-get" name="method-i-get" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Get the data stored under the given key. Returns <code>nil</code> if not
found / expired.</p>
<dl class="rdoc-list note-list"><dt>key
<dd>
<p>Key to look up (see <a href="MockDalliClient.html#method-i-set">set</a>).</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-get_source')" id="l_method-i-get_source">show</a>
              </p>
              <div id="method-i-get_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 695</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">get</span>( <span class="ruby-identifier">key</span> )
  <span class="ruby-identifier">data</span> = <span class="ruby-identifier">@@store</span>[ <span class="ruby-identifier">key</span> ]
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span>

  <span class="ruby-identifier">expires_at</span> = <span class="ruby-identifier">data</span>[ <span class="ruby-value">:expires_at</span> ]
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">expires_at</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">expires_at</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">data</span>[ <span class="ruby-value">:value</span> ]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-set">
              <b>set</b>( key, value, ttl = nil )
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-i-set" name="method-i-set" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Set data for a given key.</p>
<dl class="rdoc-list note-list"><dt>key
<dd>
<p>Key under which to store data.</p>
</dd><dt>value
<dd>
<p><a href="../../Data.html">Data</a> to store.</p>
</dd><dt><code>ttl</code>
<dd>
<p>(Optional) time-to-live (&#39;live&#39; as in living, not as in &#39;live
TV&#39;) - a value in seconds, after which the data is considered expired.
If omitted, the data does not expire.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-set_source')" id="l_method-i-set_source">show</a>
              </p>
              <div id="method-i-set_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 715</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">set</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">ttl</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-identifier">data</span> = {
    <span class="ruby-value">:expires_at</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ttl</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">utc</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ttl</span>,
    <span class="ruby-value">:value</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">value</span>
  }

  <span class="ruby-identifier">@@store</span>[ <span class="ruby-identifier">key</span> ] = <span class="ruby-identifier">data</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-stats">
              <b>stats</b>()
            <a href="../../../../classes/Hoodoo/Services/Session/MockDalliClient.html#method-i-stats" name="method-i-stats" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Mock &#39;stats&#39; health check.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-stats_source')" id="l_method-i-stats_source">show</a>
              </p>
              <div id="method-i-stats_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/services/services/session.rb, line 738</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">stats</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
